﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Xml.Serialization;
using Obra.SmugMug.Api;
using System.IO;

namespace Obra.Test.SmugMug
{
    [TestFixture]
    public class DeserializeUploadResponse
    {
        [Test]
        public void DeserializeSuccessResponse()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(UploadResponse));

            using (FileStream fileStream = new FileStream(@"..\..\SmugMug\sample\SmugMugUpload.xml", FileMode.Open))
            {
                UploadResponse response = (UploadResponse)serializer.Deserialize(fileStream);

                Assert.IsTrue(response.IsSuccess());
                Assert.AreEqual("smugmug.images.upload", response.Method);
                Assert.AreEqual(1040, response.Image.Id);
                Assert.AreEqual("ixgKE", response.Image.Key);
                Assert.AreEqual("http://example.smugmug.com/gallery/1040_FxWoe#5_qvUHy", response.Image.UrlString);
            }
        }

        [Test]
        public void DeserializeFailResponse()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(UploadResponse));

            using (FileStream fileStream = new FileStream(@"..\..\SmugMug\sample\SmugMugUploadFail.xml", FileMode.Open))
            {
                UploadResponse response = (UploadResponse)serializer.Deserialize(fileStream);

                Assert.IsFalse(response.IsSuccess());
                Assert.AreEqual("smugmug.images.upload", response.Method);
                Assert.AreEqual(4, response.Error.Code);
                Assert.AreEqual(
                    "wrong format (ByteCount given: 2538385, received: 2538385.  MD5Sum given: 2c876cf0e6305039998371a5017a2a5f, actual: f2c6fb90a9727ba2f1a58077f61e684e.)",
                    response.Error.Message);
            }
        }
    }
}
